BERLIN (AP) — Germany's mainstream conservatives led by Friedrich Merz won the country's national election, ensuring that Ukraine has an even stronger supporter in the European Union's largest country and creating hopes for renewal in an economic powerhouse that has been badly battered in recent years.

The far-right, anti-immigrant Alternative for Germany (AfD) surged to become the second-largest political force, gaining from a backlash against the high numbers of migrants and refugees the nation has absorbed over the past decade and a string of extremist attacks that has shaken its sense of security.

Merz, who is promising to unite Europe in the face of challenges from both Russia and the United States, is expected to become the country’s next leader. He vowed to do everything in his power to continue a good transatlantic relationship with the U.S., even if the Trump administration appears to have waning interest in Europe.

“If those who really do not just make ‘America First,’ but almost ‘America Alone’ their motto prevail, then it will be difficult," he told reporters Monday in his first post-election news conference. "But I remain hopeful that we will succeed in maintaining the transatlantic relationship.”

He warned that if the good relationship “is destroyed, it will not only be to the detriment of Europe, it will also be to the detriment of America.”

Markets welcomed the victory of the fiscally conservative party, with stocks in major German companies rising Monday morning on hopes for a stable coalition government that could end policy gridlock and tackle the country’s economic problems.

Merz said he wants to immediately begin negotiations with the center-left Social Democrats, who suffered a stinging defeat after their coalition collapsed. But the results were seen a rebuke for mainstream parties as AfD notched its best results ever — and the strongest for a far-right party since World War II.

The campaign was dominated by worries about the yearslong stagnation of Europe's biggest economy and large-scale migration, with Merz vowing a tough approach that continued Monday.

“None of us wants to close the borders," he told reporters. "But we need to protect our borders better. We must regain control over those who come into our country.”

The election took place against a background of growing uncertainty over the future of Ukraine and Europe's alliance with the United States.

For the time being, outgoing Chancellor Olaf Scholz, whose Social Democratic party suffered a major blow, will stay on as head of a caretaker government.

The results released by the electoral authority showed Merz’s Christian Democrats and the Social Democrats winning a combined majority of seats in the national legislature after small parties failed to make the electoral threshold. Scholz has also supported Ukraine with arms and other aid, but some Western partners have said he could have done more, and faster.

Merz said on election night that he hopes to form a government by Easter at the latest. He has ruled out a coalition with AfD and on Monday said he was “extremely worried” about the far-right party's historic gains in the election.

“We have to work together to solve the problems in Germany that are gradually removing the breeding ground for this party,” he added.

Mainstream parties hold majority as far-right surges

Merz's conservatives won 208 seats in the 630-seat Bundestag, while AfD won 152. The three parties in the former governing coalition lost seats, with SDP falling to 120 seats and the Greens to 85. The pro-business Free Democrats, which triggered early elections by pulling out of the coalition, failed to reach the 5% of the vote required to win seats.

The Left party got 64 seats, while the left-wing Sahra Wagenknecht Alliance came in just under the 5% hurdle.

AfD was jubilant on Sunday night, with leaders vowing to become the country’s main party in the next election as its appeal expands. The party has established itself as a significant political force in the 12 years since it was founded, but it hasn’t yet been part of any state or national government.

That's the result of what is often called a "firewall" against AfD. Other parties say they won't work with AfD, which is under observation by the domestic intelligence agency for suspected right-wing extremism, something the party objects to strongly. Its branches in three eastern states are designated "proven right-wing extremist" groups, which is particularly sensitive in view of Germany's Nazi past.

Yet a growing number of Germans feel that the mainstream parties have failed to manage the large-scale immigration and other problems in recent years, including responses to the COVID-19 pandemic.

The election took place seven months earlier than originally planned after Scholz's unpopular coalition collapsed in November, three years into a term that was increasingly marred by infighting. There was widespread discontent and not much enthusiasm for any of the candidates.

Merz says he's ready to face challenges from US and Russia

Merz said Monday that his top priority is to unify Europe in the face of challenges coming from the U.S. and Russia. Both U.S. Vice President JD Vance and Trump ally Elon Musk openly supported AfD.

He said he remains “hopeful that the Americans will see it as in their own interests to be involved in Europe as well.”

Still, he warned that it would be unacceptable “if the Americans strike a deal with Russia over the heads of the Europeans, over the heads of Ukraine.”

Germany is the most populous country in the 27-nation European Union and a leading member of NATO. It has been Ukraine’s second-biggest weapons supplier, after the U.S, and will be central to shaping the continent’s response to the challenges of the coming years, including the Trump administration’s confrontational foreign and trade policy. __ Geir Moulson in Berlin contributed.

Friedrich Merz, leader of the Christian Democratic Union (CDU), speaks during a news conference at the headquarters of Christian Democratic Union (CDU) party in Berlin, Germany, Monday, Feb. 24, 2025. (AP Photo/Martin Meissner)

Credit: AP

icon to expand image

Credit: AP

Friedrich Merz, left, leader of the Christian Democratic Union (CDU), stand next to Secretary General Carsten Linnemann, right, after he receives flowers at the CDU's headquarters, in Berlin, Germany, Monday, Feb. 24, 2025. (AP Photo/Martin Meissner)

Credit: AP

icon to expand image

Credit: AP

German Chancellor Olaf Scholz arrives for a news conference at the Social Democratic Party (SPD) headquarters in Berlin, Germany, Monday, Feb. 24, 2025. (AP Photo/Ebrahim Noroozi)

Credit: AP

icon to expand image

Credit: AP

German Chancellor Olaf Scholz attends a press conference of the Social Democratic Party (SPD) in Berlin, Germany, Monday, Feb. 24, 2025, the day after the national election. (AP Photo/Ebrahim Noroozi)

Credit: AP

icon to expand image

Credit: AP

Alice Weidel, right, co-leader of the Alternative for Germany Party (AfD), and Tino Chrupalla, left, co-leader of the Alternative for Germany Party (AfD), arrive for a press conference in Berlin, Germany, Monday, Feb. 24, 2025, the day after the national election. (Soeren Stache/dpa via AP)

Credit: AP

icon to expand image

Credit: AP

From left, Ines Schwerdtner, co-leader of the Left Party (Die Linke), Heidi Reichinnek, member of the German federal parliament and member of the Left Party (Die Linke) and Jan van Aken, co-leader of the Left Party (Die Linke) arrive for a press conference in Berlin, Germany, Monday, Feb. 24, 2025, the day after the national election. (AP Photo/Michael Probst)

Credit: AP

icon to expand image

Credit: AP

Sahra Wagenknecht, left, co-leader of the Sahra Wagenknecht Alliance (BSW), and Amira Mohamed Ali, right, co-leader of the Sahra Wagenknecht Alliance (BSW), arrive for a press conference in Berlin, Germany, Monday, Feb. 24, 2025, the day after the national election. (AP Photo/Michael Prost)

Credit: AP

icon to expand image

Credit: AP

Robert Habeck, Vice Chancellor and member of the Greens, during a press conference in Berlin, Germany, Monday, Feb. 24, 2025, the day after the national election. (AP Photo/Michael Prost)

Credit: AP

icon to expand image

Credit: AP

Christian Lindner, leader of the Free Democrats (FDP) party speaks during a press conference in Berlin, Germany, Monday, Feb. 24, 2025, the day after the national election (Bernd von Jutrczenka/dpa via AP)

Credit: AP

icon to expand image

Credit: AP

Cars move towards the Brandenburg Gate on the 17th of June Street in Berlin , Germany, Monday, Feb. 24, 2025, the day after the German election. (AP Photo/Michael Probst)

Credit: AP

icon to expand image

Credit: AP